<?php
class ScoreExt {
    public static function add($uid,$score,$scoreType,$reason,$urlDesc,$url,$img){
        $obj = new ScoreLog();
        //检查今天或者本月是否达到上限
        $day = date('Y-m-d');
        $sql = "SELECT SUM(score) as totalScore FROM ".$obj->table()." WHERE uid=".$uid." AND created LIKE '$day%' ";
        $one = $obj->one($sql);
        if($one['totalScore']>50) return false;

        $obj = new ScoreLog();
        $obj->uid = $uid;
        $obj->score = $score;
        $obj->scoreType = $scoreType;
        $obj->reason = $reason;
        $obj->info = $urlDesc;
        $obj->url  = $url;
        $obj->img = $img;
        $obj->ip = myip::getIp();
        $obj->save();


        //计算用户的积分
        $sql = "SELECT SUM(score) as totalScore FROM ".$obj->table()." WHERE uid=".$uid;
        $one = $obj->one($sql);
        $totalScore = $one['totalScore'];
        $user = new User();
        $user->find($uid);
        $user->score = $totalScore;
        $user->save();


    }



}